<template>
  <div class="cart-bottom-bar flex">
    <div class="check_div" >
      <input type="checkbox" class="check" id="check" :checked="ToFullChecked" @click="toGetFullChecked()">&ensp;
      <label for="check" class="label1">全选</label>
    </div>
    <div class="getSum">
      <div class="get_sum">
        合计： ￥{{toNumFixed(toGetSum().sum)}}
      </div>
      <div class="get_count">去结算({{toGetSum().isCheckCount}})</div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "CartBottomBar",
    data(){
      return{
        CartGoodsList:this.$store.state.Cart,


      }
    },
    computed:{
      ToFullChecked(){
        if (this.CartGoodsList.length===0)return false
        for(let item of this.CartGoodsList){
          if (!item.isChecked){
            return false
          }
        }
        return true
      },




    },

    methods:{
      toGetSum(){
        let sum=0;
        let isCheckCount=0;
        for (let item of this.CartGoodsList){
          if(item.isChecked===true){
            sum+= item.count *item.price;
            isCheckCount+=item.count;
          }
        }
        return {sum,isCheckCount}
      },
      toGetFullChecked(){
        //console.log(this.ToFullChecked);
        if(this.ToFullChecked) {
          this.CartGoodsList.forEach(
              (item)=>{
                item.isChecked=false
              }
          )
        }else {
          this.CartGoodsList.forEach(
              (item)=>{
                item.isChecked=true
              }
          )
        }
      },
      toNumFixed(value){
        return (value/1).toFixed(2)
      }

    }
  }
</script>

<style scoped>
  .cart-bottom-bar{
    position: fixed;
    height: 41px;
    bottom:49px;
    left: 0;
    right: 0;
    background-color: #fff;
    justify-content: space-between;

  }
  .flex{
    display: flex;
  }
  .cart-bottom-bar div{
    line-height: 41px;
    font-size: 14px;
    text-align: center;
  }
  .check_div{

  }

  .getSum{
    display: flex;
    width: 70%
  }
  .getSum div{
    width: 50%;

  }
  .get_sum{

  }
  .get_count{
    background-color: #ef4136;
  }


</style>